package io;

import org.junit.jupiter.api.Test;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;

/**
 * Author: hu
 * Date: 2022/3/1 09:48
 */
public class IoStream{
    public static void main(String[] args) throws Exception {
        //1创建字节文件输入流
        File f = new File("top/src/io/IoStream.java");
        FileInputStream fis = new FileInputStream(f);
        BufferedInputStream bis = new BufferedInputStream(fis);
        //2读取文件
        byte[] buf = new byte[128];
        int data;
        while((data=bis.read(buf))!=-1){
            System.out.print(new String(buf,0,data));
            Thread.sleep(100);
        }
        //3关闭流
        fis.close();

        File oop = new File("top/src/oop");
        System.out.println(oop.exists());
        System.out.println(oop.isDirectory());
        System.out.println(oop.isFile());
        System.out.println(oop.canRead());
        if(oop.isDirectory()){
            String[] files = oop.list();
            for (String str:files) {
                System.out.println(str);
            }

        }
        File[] fs =oop.listFiles();

    }
    @Test
    public void test(){
        System.out.println(hashCode());
        ArrayList<String> aa = new ArrayList<>();
    }

}
